-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Stories from markdown #345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Omg you're hilarious. Yassss! 🎉 Without reviewing the code or reading the mdast docs, would we be able to mark certain stories in the readme that we want pulled in? Asking as I don't think we'd want all of the code snippets within a readme pulled in, though I think we could make that work with some readme improvements. Also, how do they get their name in the sidebar? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A woohoo 🦆
|
This is definitely WIP. Let's discuss tomorrow. |
|
I got a bug in my brain about how to do the titles, and added support for excluding code blocks (because it seemed to me that blacklisting was better than whitelisting). See the updated PR description for how it works! After e02bd53, the Storybook UI shows this: |
|
Okay @broccolini, now primer-breadcrumb is the only module that uses this, and the usage example has |

This adds a helper function that can import Storybook stories from fenced code blocks in markdown files. It's surprisingly easy, thanks to remark and unist plugins!
JS
In a module's
stories.jsorstories/*.jsfile:Note:
require.context()is a webpack thing that facilitates dynamicrequire()statements. I've added theraw-loaderper these instructions, which is how webpack is able to read the markdown files as strings when you do something likerequire('README.md').Markdown
In your
README.mdordocs/*.md, write fenced code blocks with thehtmllang and optional metadata in key-value pairs. The following rules apply:Code blocks with
story=false(orstory="false") will be ignored.The
titlemetadata can be used to provide an explicit title for each code block:Otherwise, the text of the preceding heading will be used as the title, as in:
Because titles can't be repeated, multiple code blocks preceded by a single heading will get placeholder titles in the form
story @ {file}:{line}.And that's it! For a working example, see primer-breadcrumb/stories.js and the accompanying README.md.
/cc @primer/ds-core